{include file='Public/header' /}
<div class="layui-layout layui-layout-admin">
{include file='Public/head' /}	
{include file='Public/side' /}
<div class="layui-body"> 
{include file='Public/crumbs' /}
	<!-- 内容主体区域 -->
	<div class="shu-body">
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12 layui-col-xs12">
					<form class="layui-form" method="post">
						<input type="hidden" name="pid" id="pid"  value="{$pid}">
						<a href="{:url('add?pid='.$pid)}" class="layui-btn"><i class="layui-icon">&#xe61f;</i> 添加</a>
						<table lay-even class="layui-table">
							<colgroup>
							<col width="50">
							</colgroup>
							<thead>
								<tr>
									<th> 
									<input type="checkbox" name="checkAll" lay-filter="checkAll">
									</th>
									<th>名称</th>
									<th>分类</th>
									<th>图片</th>
                                    <th>链接</th>
                                    <th>排序</th>
                                    <th>操作</th>
								</tr>
							</thead>
							<tbody>
							{volist name="list" id="val"}
							<tr>
								<td align="center"> 
								<input type="checkbox" name="ids[{$val['id']}]" lay-filter="checkOne" value="{$val['id']}">
								</td>
								<td>{$val['title']}</td>
								<td>
										{if condition="$val['classid'] eq 1"}
										幻灯
										{/if}
										{if condition="$val['classid'] eq 2"}
										内页幻灯
										{/if}
										{if condition="$val['classid'] eq 3"}
										手机幻灯
										{/if}
								</td>
								<td>
                                            {if condition="$val['pic'] neq ''"}
											<img src="__ROOT__{$val['pic']}"width="88" height="31">
                                            {else/}
                                            无图
                                            {/if}
                                </td>
								<td>
								<a href="{$val['url']}" target="_blank">{$val['url']}</a>
								</td>
								<td><input style="width:150px;" name="o" class="inputorder layui-input" type="number" value="{$val['o']}" val="{$val['id']}"/>
								</td>
								<td>
								<a class="layui-btn layui-btn-small" href="{:url('edit',array('id'=>$val['id']))}">修改</a>
								 
								<a class="layui-btn layui-btn-small layui-btn-danger del_btn"  href="javascript:;" nickname="{$val['title']}" val="{:url('del',array('ids'=>$val['id']))}">删除</a> 
								 
								</td>
							</tr>
							{/volist}
							</tbody>
						</table>
						<a class="layui-btn" lay-submit lay-filter="delete"><i class="layui-icon">&#xe640;</i> 批量删除</a>
						<div class="shu-page">
						 
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- 内容主体区域 END--> 
</div>
{include file='Public/footer' /} 
<script>
layui.use('form',function(){
  var form = layui.form,
  jq = layui.jquery;
  
	//排序
	jq(".inputorder").change(function () {
		var id = jq(this).attr('val');
		var o = jq(this).val();
		if (id != o) {
			loading = layer.load(2, {
				shade: [0.2,'#000']
	  		});
			jq.post("{:url('update',array('act'=>'order'))}", {id: id, o: o}, function (data) {
				console.log(o);
				if(data.code == 1){
				  layer.close(loading);
				  layer.msg(data.msg, {icon: 1, time: 1000}, function(){
					//location.reload();
				  });
				}else{
				  layer.close(loading);
				  layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
				}
			});
		}
	});

  form.on('checkbox(checkAll)', function(data){
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").prop('checked',true);
    }else{
      jq("input[lay-filter='checkOne']").prop('checked',false);
    }
    form.render('checkbox');
  });  

  form.on('checkbox(checkOne)', function(data){
    var is_check = true;
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").each(function(){
        if(!jq(this).prop('checked')){ is_check = false; }
      });
      if(is_check){
        jq("input[lay-filter='checkAll']").prop('checked',true);
      }
    }else{
      jq("input[lay-filter='checkAll']").prop('checked',false);
    } 
    form.render('checkbox');
  });
  
  jq('.del_btn').click(function(){
	var name = jq(this).attr('nickname');
    var url = jq(this).attr('val');
    layer.confirm('确定删除【'+name+'】?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.get(url,function(data){
        if(data.code == 1){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else if(data.code == 0){
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });   
  });

  form.on('submit(delete)', function(data){
    var is_check = false;
    jq("input[lay-filter='checkOne']").each(function(){
      if(jq(this).prop('checked')){ is_check = true; }
    });
    if(!is_check){
      layer.msg('请选择数据', {icon: 2,anim: 6,time: 1000});
      return false;
    }
    layer.confirm('确定批量删除?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      var param = data.field;
      jq.post("{:url('del')}",param,function(data){
        if(data.code == 1){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else if(data.code == 0){
          layer.close(loading);
          layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
        }
      });
    });
	
    return false;
  });
  
 
})
</script> 
